<template>
  <div>
    <Handle class="handle" type="target" :position="Position.Top" />
    <div
      :class="{
        input: props.type === 'input',
        output: props.type === 'output',
        'is-focus': store.currentNode?.id === props.id
      }"
      class="node"
    >
      <span class="node__content">
        {{ props.type === 'custom' ? props.data.scriptInfo?.name : props.data.label }}
      </span>
    </div>
    <Handle class="handle" type="source" :position="Position.Bottom" />
  </div>
</template>

<script setup lang="ts">
import { useFlowStore } from '@/store/modules/flow'
import { FlowCustomData } from '@/types'
import type { NodeProps, CustomEvent } from '@vue-flow/core'
import { Position, Handle } from '@vue-flow/core'

const props = defineProps<NodeProps<FlowCustomData, Record<string, CustomEvent>>>()

const store = useFlowStore()
</script>

<style lang="less" scoped>
/* 基础样式 */
.node {
  border: 2px solid #4a9eff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 8px 16px;
  min-width: 120px;
  transition: all 0.2s ease;
  box-sizing: border-box;

  // 在原有样式基础上增加
  position: relative;
  background: linear-gradient(145deg, #f8f9ff, #ffffff);

  // 渐变光晕边框
  &::before {
    content: '';
    position: absolute;
    inset: -3px;
    background: linear-gradient(45deg, #4a9eff, #85b8ff, #c1d9ff);
    border-radius: 10px;
    z-index: -1;
    filter: blur(4px);
    opacity: 0.3;
    transition: opacity 0.3s;
  }

  &.is-focus {
    background: #4a9eff;
    .node__content {
      font-weight: bolder;
      color: #fff;
    }
  }
}

/* 内容样式 */
.node__content {
  color: #2c3e50;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  display: block;
  text-align: center;
  white-space: nowrap;

  /* 新增省略号样式 */
  max-width: 200px; // 根据节点尺寸调整
  overflow: hidden;
  text-overflow: ellipsis;
}

.node.selected {
  background: #f0f7ff;
  border-color: #297acc;
}

/* 连接点样式调整（需配合 Handle 组件） */
.handle {
  width: 6px;
  height: 6px;
  background: #fff;
  border: 2px solid #4a9eff;
}

.node__badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ffd700;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  .iconfont {
    font-size: 14px;
    color: #2c3e50;
  }
}
</style>
